package com.cty;

import com.cty.mapper.EmployeeMapper;
import com.cty.pojo.Employee;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {
    public SqlSession sqlSession;

    @BeforeEach
    public void before() throws IOException {
        InputStream inputStream =
                Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory =
                new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession= sqlSessionFactory.openSession(true);
    }

    @AfterEach
    public void after() {
        sqlSession.close();
    }

    @Test
    public void test_01() {
        EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
        //开启sql分页插件
        //注意:在插件开启和结束的区域内只能有一条查询语句
        //注意sql语句后面不要加;
        PageHelper.startPage(1, 2);
        List<Employee> employeeList= mapper.queryByNameAndBySalary("cty",500.0);
        //获得这个分页的对象，里面可以获得这个分页的各项数据
        PageInfo<Employee> pageInfo = new PageInfo<>();
    }
}
